<template>
  <div>
    <h2>登录页面</h2>用户名
    <input type="text" v-model="username" />
    密码
    <input type="text" v-model="password" />
    <button @click="sub">登陆</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "",
      password: ""
    };
  },
  methods: {
    sub: function() {
      let data = {
        username: this.username,
        password: this.password
      };

      this.axios({
        url: "http://127.0.0.1:8000/app01/login/",
        method: "post",
        data: data
      }).then(res => {
        if (res.data.code == 1000) {
          //1
          localStorage.setItem("uid", res.data.data);
          //2
          this.$router.push("/");
        } else {
          alert(res.data.msg);
        }
      });
    }
  }
};
</script>

<style>
</style>